package com.zmx.patientend.view.activity;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
import androidx.fragment.app.FragmentPagerAdapter;
import androidx.viewpager.widget.ViewPager;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import com.google.android.material.tabs.TabLayout;
import com.zmx.patientend.BaseActivity;
import com.zmx.patientend.R;
import com.zmx.patientend.fragment.HomeFragment;
import com.zmx.patientend.fragment.friends.FocusOnFragment;
import com.zmx.patientend.fragment.friends.RecommendedFragment;
import com.zmx.patientend.fragment.live.LiveIngFragment;
import com.zmx.patientend.fragment.live.LiveTrailerFragment;

import java.util.ArrayList;
import java.util.List;

/**
*时间：2020/7/16 16:58
*功能：朋友圈
*/
public class CircleOfFriendsActivity extends BaseActivity {

    static final int NUM_ITEMS = 2;
    private List<Fragment> fragmentList = new ArrayList<Fragment>();
    private String[] strings = new String[]{"推荐","最新"};
    private ImageButton add_button;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_circle_of_friends;
    }

    @Override
    protected void initViews() {
        setToolbar(R.id.tool_bar);

        add_button = findViewById(R.id.add_button);
        add_button.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent = new Intent();
                intent.setClass(mActivity, ReleaseFriendsActivity.class);
                startActivity(intent);

            }
        });

        RecommendedFragment lif = new RecommendedFragment();
        FocusOnFragment ltf = new FocusOnFragment();

        fragmentList.add(lif);
        fragmentList.add(ltf);

        initView();

    }

    private void initView(){

        TabLayout tab_layout = findViewById(R.id.tab_layout);
        ViewPager viewPager = findViewById(R.id.viewPager);
        CircleOfFriendsActivity.MyAdapter fragmentAdater = new CircleOfFriendsActivity.MyAdapter(getSupportFragmentManager());
        viewPager.setAdapter(fragmentAdater);
        tab_layout.setupWithViewPager(viewPager);

    }


    public class MyAdapter extends FragmentPagerAdapter {
        public MyAdapter(FragmentManager fm) {
            super(fm);
        }

        @Override
        public int getCount() {
            return NUM_ITEMS;
        }

        @Override
        public Fragment getItem(int position) {
            return fragmentList.get(position);
        }

        @Nullable
        @Override
        public CharSequence getPageTitle(int position) {
            return strings[position];
        }
    }

}
